package com.sugon.controller.spare;

import com.sugon.annotation.AutoLog;
import com.sugon.entity.SparePartTransactionRecordEntity;
import com.sugon.service.SparePartTransactionRecordService;
import com.sugon.utils.PageUtils;
import com.sugon.utils.Query;
import com.sugon.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 备件事务记录Controller
 *
 * @author YuXD
 * @date 2022-09-05
 */
@Controller
@RequestMapping("spareparttransactionrecord")
public class SparePartTransactionRecordController {
    @Autowired
    private SparePartTransactionRecordService sparePartTransactionRecordService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
    @ResponseBody
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<SparePartTransactionRecordEntity> sparePartTransactionRecordList = sparePartTransactionRecordService.queryList(query);
        int total = sparePartTransactionRecordService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(sparePartTransactionRecordList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
    @ResponseBody
    public R info(@PathVariable("id") String id) {
        SparePartTransactionRecordEntity sparePartTransactionRecord = sparePartTransactionRecordService.queryObject(id);

        return R.ok().put("sparePartTransactionRecord", sparePartTransactionRecord);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @ResponseBody
    public R save(@RequestBody SparePartTransactionRecordEntity sparePartTransactionRecord) {
        sparePartTransactionRecordService.save(sparePartTransactionRecord);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @ResponseBody
    public R update(@RequestBody SparePartTransactionRecordEntity sparePartTransactionRecord) {
        sparePartTransactionRecordService.update(sparePartTransactionRecord);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @ResponseBody
    public R delete(@RequestBody String[] ids) {
        sparePartTransactionRecordService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    @ResponseBody
    public R queryAll(@RequestParam Map<String, Object> params) {
        List<SparePartTransactionRecordEntity> list = sparePartTransactionRecordService.queryList(params);
        return R.ok().put("list", list);
    }

}
